package com.shiliao.app.weight.dialog;

import android.app.Activity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.shiliao.app.R;
import com.shiliao.app.activity.index.adapter.ExamineAdapter;
import com.shiliao.app.activity.index.entity.WaitExamineEntity;
import com.shiliao.app.activity.interlocution.dialog.SimilarQuestionAdapter;
import com.yimei.framework.ui.dilaog.AnimationType;
import com.yimei.framework.ui.dilaog.YimeiBaseDialog;

import java.util.List;

/**
 * Created by yinzhiqiang on 2018/5/21.
 */

public class NewExamineDialog extends YimeiBaseDialog implements ExamineAdapter.CheckQuestion{
    private RecyclerView recyclerView;
    private ImageView close;
    private ExamineAdapter adapter;
    private TextView commitChoice;
    private String id;
    public NewExamineDialog(Activity mActivity, List<WaitExamineEntity> entities) {
        super(mActivity);
        mContainerView = getLayoutInflater().inflate(R.layout.dialog_checkout_examin, null);
        close =  mContainerView.findViewById(R.id.iv_close);
        commitChoice =  mContainerView.findViewById(R.id.btn_commit_choice);
        recyclerView = (RecyclerView) mContainerView.findViewById(R.id.question_lv);
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        adapter = new ExamineAdapter(mActivity, R.layout.item_choice_exmain, entities, this);
        recyclerView.setAdapter(adapter);

        mWindow.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER);
        mWindow.setWindowAnimations(mAnimations[AnimationType.TOAST_FADE
                .getValue()]);
        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    @Override
    public void clickCheck(String position) {
        id=position;
    }

    public void commit(View.OnClickListener listener){
        commitChoice.setOnClickListener(listener);
    }

    public String getResult(){
        if (!TextUtils.isEmpty(id)) {
            return id;
        }else{
            return "1";
        }
    }

    @Override
    public void show(boolean isAutoDismiss) {
        super.show(isAutoDismiss);
        WindowManager.LayoutParams params = mWindow.getAttributes();
        WindowManager windowManager = mActivity.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        params.width = (int) (display.getWidth() * 0.9);
//        mWindow.setBackgroundDrawableResource(R.drawable);
        mWindow.setAttributes(params);
    }

}
